/*开发作者:seawan
 * 时间:2007/9/13
 * 版本1.0
 * 基本功能:向客户端发送指令
 * 方法及变量说明:本程序实现了对客户端操作的功能,当服务器端运行时,客户端接入,
                 服务器端会显示提示信息,按提示信息操作会得到相应的结果.
 */

package onlineClient;

import java.io.*;
import java.net.*;

public class Server {
    //主函数，抛出异常
	public static void main(String[] args) throws IOException {
        //创建服务器监听
		ServerSocket ss = new ServerSocket(8888);
		System.out.println("关机请按1");
		System.out.println("取消关机请按2");
		System.out.println("播放音乐请按3");
		System.out.println("显示图片请按4");
		System.out.println("删除指定文件请按５");
		try{
			System.out.println("等待客户端连接...");
            //声明服务器接口
			Socket s = new Socket();
            //监听客户端连接
			s = ss.accept();
            //创建输入流
			BufferedReader in = new BufferedReader(new InputStreamReader(s
					.getInputStream()));
			//创建系统输入
			BufferedReader inkey = new BufferedReader(
					new InputStreamReader(System.in));
			//创建输出流
			PrintWriter out = new PrintWriter(new BufferedWriter(
					new OutputStreamWriter(s.getOutputStream())), true);
			//循环监听
			while(true){
				System.out.print("Server:");
				String rnmsg = inkey.readLine();
				out.println(rnmsg);
				String getmsg = in.readLine();
				System.out.println("Client:"+getmsg);
				
			}
		}
		//捕获异常处理
		catch(Exception e)
		{
		System.out.println(e.getMessage());
		}
		finally{
			ss.close();//关闭端口
		}
	}
}